<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-default navbar-btn" href="${base}/platform/ud/coupon" data-pjax  ><i class="ti-angle-left" id="goback"></i> 返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;height: 100%;">
            <form id="couponAddForm" role="form" class="form-horizontal parsley-form" data-parsley-validate 
                  action="${base}/platform/ud/coupon/addDo" method="post">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="coupon_name" class="col-sm-2 control-label">优惠券名称</label>

                            <div class="col-sm-8">
                                <input type="text" id="coupon_name" class="form-control" name="coupon_name" data-parsley-required="true" data-parsley-maxlength="100" placeholder="优惠券名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="coupon_sub_title" class="col-sm-2 control-label">券名</label>

                            <div class="col-sm-8">
                                <input type="text" id="coupon_sub_title" class="form-control" name="coupon_sub_title"   data-parsley-required="true" data-parsley-maxlength="20" placeholder="券名">
                            </div>
                        </div>
                        <div class="form-group">
                                <label for="coupon_logo" class="col-sm-2 control-label">logo</label>

                                <div class="col-sm-8">
                                    <div id="queue"></div>
                                    <div>
                                        <input id="file_upload" name="file_upload" type="file" multiple="false">
                                    </div>
                                    <div id="img" style="padding: 5px;">
                                    </div>
                                    <input type="hidden" id="coupon_logo" name="coupon_logo" value="" >
                                </div>
                            </div>
                        <div class="form-group">
                            <label for="coupon_notice" class="col-sm-2 control-label">卡券使用提醒</label>

                            <div class="col-sm-8">
                                <input type="text" id="coupon_notice" class="form-control" name="coupon_notice" data-parsley-required="true" data-parsley-maxlength="50" placeholder="卡券使用提醒">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="coupon_fee" class="col-sm-2 control-label">额度</label>
                            
                            <div class="col-sm-8">
                                <input type="text" id="coupon_fee" class="form-control" name="coupon_fee" data-parsley-required="true" data-parsley-type="number" placeholder="额度">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="coupon_date_type" class="col-sm-2 control-label">使用时间类型</label>
                            
                            <div class="col-sm-8">
                                <input type="radio" name="coupon_date_type" data-parsley-required="true" value="0" onclick="chooseDate(this.value)" />固定日期
                                <input type="radio" name="coupon_date_type" data-parsley-required="true" value="1" onclick="chooseDate(this.value)" />固定时长
                            </div>
                        </div>
                        <div id="FIX_TIME_RANGE" style="display: none">
	                        <div class="form-group" >
	                           	<label for="coupon_begin_timestamp" class="col-sm-2 control-label">启用时间</label>
	                           	
	                            <div class="col-sm-3">
	                                <input type="text" id="coupon_begin_timestamp" class="form-control"   name="coupon_begin_timestamp_str" value="" />
	                            </div>
	                        </div>
	                        <div class="form-group">
	                           <label for="coupon_end_timestamp" class="col-sm-2 control-label">结束时间</label>
	                           	
	                            <div class="col-sm-3">
	                                <input type="text" id="coupon_end_timestamp" class="form-control"  name="coupon_end_timestamp_str" value="" />
	                            </div>
	                        </div>
                        </div>
                        <div class="form-group" id="FIX_TERM"  style="display: none">
                            <label for="coupon_fixed_term" class="col-sm-2 control-label">时长</label>
                            
                            <div class="col-sm-8">
                               <input type="text" id="coupon_fixed_term" class="form-control" name="coupon_fixed_term"  data-parsley-type="number" placeholder="时长（天）">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="coupon_quantity" class="col-sm-2 control-label">数量</label>
                            
                            <div class="col-sm-8">
                                <input type="text" id="coupon_quantity" class="form-control" name="coupon_quantity" data-parsley-required="true"  data-parsley-type="number" placeholder="数量">
                            </div>
                        </div>
                        <div class="form-group" >
	                    	<label for="max_num" class="col-sm-2 control-label">每人领取数</label>
	                            
	                        <div class="col-sm-8">
	                 	       <input type="text"   id="max_num" class="form-control" name="max_num"  data-parsley-required="true"  data-parsley-type="number" placeholder="数量（张）">
	                        </div>
	                    </div>
                        <div class="form-group">
                            <label for="coupon_synopsis" class="col-sm-2 control-label">简介</label>
                            
                            <div class="col-sm-8">
                                <input type="text" id="coupon_synopsis" class="form-control" name="coupon_synopsis" data-parsley-required="true"  placeholder="简介">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="coupon_remark" class="col-sm-2 control-label">备注</label>
                            
                            <div class="col-sm-8">
                                <input type="text" id="coupon_remark" class="form-control" name="coupon_remark" data-parsley-required="true"  placeholder="备注">
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3"></div>
                	<div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>
                        <div>
                        	<button class="btn btn-primary navbar-btn" type="button" id="save"> 保存</button>
                        </div>
                    </div>
                </div>
                </div>
            </form>
    </div>
</div>
<a class="exit-offscreen"></a>
<script language="JavaScript">
	function clearFile() {
	    $("#img").html("");
	    $("#queue").html("");
	    $("#picurl").val("");
	}
    $(document).ready(function () {
    	 $.datetimepicker.setLocale('ch');
         $('#coupon_begin_timestamp').datetimepicker({
          	lang:'ch',
          	format:'Y-m-d H:i:s'
         });
         $('#coupon_end_timestamp').datetimepicker({
          	lang:'ch',
          	format:'Y-m-d H:i:s'
         });
    	$('#file_upload').uploadifive({
             'auto': true,
             'multi': false,
             'width': '100%',
             'height': '35',
             'buttonText': '请选择图片',
             'fileType': 'image/*',
             'fileSizeLimit': 1024,
             'queueSizeLimit': 1,
             'formData': {},
             'queueID': 'queue',
             'uploadScript': '${base}/open/file/upload/image',
             'onUploadComplete': function (file, data) {
                 data = JSON.parse(data);
                 if (data.code == 0) {
                     Toast.success(data.msg);
                     $("#img").html("<img src='${AppUploadRoot}" + data.data + "' style='width:150px;height:95px;'>");
                     $("#coupon_logo").val(data.data);
                 } else {
                     clearFile();
                     Toast.error(data.msg);
                 }
             },
             'onDrop': function (file, fileDropCount) {
                 clearFile();
             },
             'onClearQueue': function (queue) {
                 clearFile();
             },
             'onCancel': function () {
                 clearFile();
             }
         });
    	 $("#save").on("click",function(){
             $('#couponAddForm').submit();
         });
      	$('#couponAddForm').ajaxForm({
      		dataType: 'json',
      		beforeSubmit: function (arr, form, options) {
            },
            success: function (data, statusText, xhr, form) {
                if (data.code==0) {
                	 Toast.success(data.msg);
                     setTimeout(function () {
                         $("#goback").trigger("click");
                     }, 1000);
                } else {
                    Toast.error(data.msg);
                }
            }
        });  
    });
    
    //使用时间类型
    function chooseDate(value){
    	if(value==0){
    		$("#FIX_TIME_RANGE").css('display','block'); 
    		$("#FIX_TERM").css('display','none'); 
    		$("#coupon_fixed_term").removeAttr('data-parsley-required'); 
    		
    		//清空数据
    		$("#coupon_fixed_term").val("");
    	}
    	if(value==1){
    		$("#FIX_TERM").css('display','block'); 
    		$("#FIX_TIME_RANGE").css('display','none'); 
    		$("#coupon_fixed_term").attr('data-parsley-required','true'); 
    		//清空数据
    		$("#coupon_begin_timestamp").val("");
    		$("#coupon_end_timestamp").val("");
    	}
    }
  
</script>
<%}%>